
package jgf.beans;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;
import jgf.Arc;
import jgf.Attribute;

/**
 * This bean is a piece of information about a generic Arc.
 * It manages all the information relevant to an Arc,
 * i.e. The ID, the label, the 'from' and 'to' Nodes, the list of attributes
 * and the ID of the graph which this Arc belong to.<br />
 * This class should be totally populated to avoid undesired effects.
 * The list of attributes represented here should correspond with
 * the default list of the graph for arcs (only the key set).
 * @author Marcos Garcia Ortega <a href="mailto:thiamath@gmail.com">&lt;thiamath@gmail.com&gt;</a>
 */
public class ArcBean  implements Serializable{

    protected Integer graphId;

	protected Integer id;
    protected Integer fromId;
    protected Integer toId;
    protected String label;
    protected TreeMap<String, Attribute> attributes;

    public ArcBean() {
        attributes = new TreeMap<String, Attribute>();
    }

	public ArcBean(Arc arc) {
		id = arc.getId();
		fromId = arc.getFrom().getId();
		toId = arc.getTo().getId();
		label = arc.getLabel();
		for (Attribute attribute : arc.getAttributeList()) {
			attributes.put(attribute.getName(), attribute);
		}
	}

    /**
     * Gets the list of attributes assignated to the arc.
     * @return A List of Attribute.
     */
    public List<Attribute> getAttributes() {
        ArrayList<Attribute> ret = new ArrayList<Attribute>();

        for (String key : attributes.keySet()) {
            ret.add(attributes.get(key));
        }

        return ret;
    }

	public Attribute getAttribute(String name) {
		return attributes.get(name);
	}

    /**
     * Sets the list of attributes for this arc.
     * @param attributes A List of Attribute.
     */
    public void setAttributes(List<Attribute> attributes) {
        for (Attribute att : attributes) {
            this.attributes.put(att.getName(), att);
        }
    }

	/**
	 * Gets the ID number of this arc.
	 * @return An Integer with the ID number of this arc.
	 */
	public Integer getId() {
		return id;
	}

	/**
	 * Sets the ID number for this arc.
	 * @return An Integer with the ID number of this arc.
	 */
	public void setId(Integer id) {
		this.id = id;
	}

    /**
     * Gets the ID number of the node where this arc leaves from.
     * @return An Integer with the ID number of the 'from' node.
     */
    public Integer getFromId() {
        return fromId;
    }

    /**
     * Sets the ID number of the node where this arc leaves from.
     * @param fromId An Integer with the ID number of the 'from' node.
     */
    public void setFromId(Integer fromId) {
        this.fromId = fromId;
    }

    /**
     * Gets the ID number of the graph which this arc belong to.
     * @return An Integer with the ID number of the owner graph.
     */
    public Integer getGraphId() {
        return graphId;
    }

    /**
     * Sets the ID number of the graph which this arc belong to.
     * @param graphId An Integer with the ID number of the owner graph.
     */
    public void setGraphId(Integer graphId) {
        this.graphId = graphId;
    }

    /**
     * Gets the label of the arc.
     * @return A String with the label of the arc.
     */
    public String getLabel() {
        return label;
    }

    /**
     * Sets the label of the arc.
     * @param label A String with the label of the arc.
     */
    public void setLabel(String label) {
        this.label = label;
    }

    /**
     * Gets the ID number of the node where this arc arrives to.
     * @return An Integer with the ID number of the 'to' node.
     */
    public Integer getToId() {
        return toId;
    }

    /**
     * Sets the ID number of the node where this arc arrives to.
     * @param graphId An Integer with the ID number of the 'to' node.
     */
    public void setToId(Integer toId) {
        this.toId = toId;
    }


}